const { spawn } = require('child_process');
const path = require('path');

console.log('Starting collaborative editor development environment...');

// 启动后端服务器
const backend = spawn('node', ['index.js'], {
  cwd: path.join(__dirname, 'server'),
  stdio: 'inherit'
});

// 启动前端开发服务器
const frontend = spawn('npm', ['run', 'dev'], {
  cwd: __dirname,
  stdio: 'inherit'
});

// 错误处理
backend.on('error', (error) => {
  console.error('Backend server error:', error);
});

frontend.on('error', (error) => {
  console.error('Frontend server error:', error);
});

// 退出处理
process.on('SIGINT', () => {
  console.log('Shutting down development environment...');
  backend.kill();
  frontend.kill();
  process.exit(0);
});

console.log('Development environment started successfully!');
console.log('Frontend: http://localhost:5173');
console.log('Backend: http://localhost:3000');